var app = getApp();
const pathUrl = app.globalData.pathUrl;
Page({
  data: {
    pathUrl: pathUrl,
    openId: '',
    proNo: '',
    orderNo: '',
    proIsdb: '', //是否有担保人1是
    proAttList: [], //上传附件列表
    array: ['否', '是'],
    number:'1',
    pickerIndex:'1',
    orderPeriod:'是',
    array1: ['贷款金额', '附加金额'],
    number1:'1',
    pickerIndex1:'0',
    orderPeriod1:'贷款金额',
    flag: true,
    isSubmit: true,
    cocomId:'140804150841'
  },
  onLoad: function (e) {

    var openId = wx.getStorageSync('openId');
    var proNo = e.proNo;
    var proName = e.proName;
    var orderNo = e.orderNo;
    var type = e.type;
    var nameNumber = e.nameNumber;

    this.setData({
      proNo: proNo,
      openId: openId,
      orderNo: orderNo,
      type: type,
      nameNumber: nameNumber
    })
    wx.setNavigationBarTitle({
      title: proName
    })
    console.log("proNo:" + proNo)
    // this.getProAttList();
    this.getfqjj();
  },


  getfqjj:function(){
    var that = this ;
    wx.request({
      url: pathUrl +'/rest/hrfqjj02Controller/list/' +that.data.openId,
      data:{
        pageNumber:'1',
        pageSize:'10',
        fxjOut01:that.data.orderNo,
        fxjOut02: that.data.type,
      },
      method:'GET',
      success:function(e){
        console.log(e.data)
        if(e.data.data== null || e.data.data == ''){
          return false;
        }
        that.setData({
          cocomId: e.data.data[0].cocomId,
          cocomInterestNo: e.data.data[0].cocomInterestNo,
          cocomReceiveAmt: e.data.data[0].cocomReceiveAmt,
        })
        if (e.data.data[0].cocomInterestFlag =='0'){
          that.setData({
            pickerIndex: '0',
            orderPeriod: '否',
            number: '0'
          })
         
        }else{
          that.setData({
          pickerIndex: '1',
          orderPeriod: '是',
          number: '1'
          })

        }
        if (e.data.data[0].cocomReceiveType=='1'){
          that.setData({
            pickerIndex1: '0',
            orderPeriod1: '贷款金额',
            number1: '1'
          })
        }else{
          that.setData({
            pickerIndex1: '1',
            orderPeriod1: '附加金额',
            number1: '2'
          })
        }
      }
    })
  },

  bindRelationship: function (e) {
    var index = e.detail.value;
    var orderPeriod = this.data.array[index];
    var number = null;
    this.setData({
      number: index,
      pickerIndex: index,
      orderPeriod: orderPeriod
    })

  },
  bindRelationship1: function (e) {
    var index = e.detail.value;
    var orderPeriod1 = this.data.array1[index];
    var number1 = Number(index) + 1;
    this.setData({
      number1: number1,
      pickerIndex1: index,
      orderPeriod1: orderPeriod1
    })
  },
  cocomId: function (e) {
    this.setData({
      cocomId: e.detail.value
    })
  },
  cocomInterestNo: function (e) {
    this.setData({
      cocomInterestNo: e.detail.value
    })
  },
  cocomReceiveAmt: function (e) {
    this.setData({
      cocomReceiveAmt: e.detail.value
    })
  },
  submitBtn: function () {
    var that = this;
    if (that.data.isSubmit) {
      that.setData({
        isSubmit: false
      });
      var data = {
        cocomId: that.data.cocomId,
        cocomInterestFlag: that.data.number,
        cocomInterestNo: that.data.cocomInterestNo,
        cocomReceiveAmt: that.data.cocomReceiveAmt,
        cocomReceiveType: that.data.number1,
        fxjOut01:that.data.orderNo,
        fxjOut02: that.data.type,

      };
      console.log("data:" + JSON.stringify(data));
      wx.request({
        url: pathUrl + '/rest/hrfqjj02Controller',
        data: data,
        method: 'POST',
        success: function (res) {
          console.log(res.data)
          if (res.data.ok) {
            that.setData({
              isSubmit: true
            });
            wx.showToast({
              title: '提交成功',
              duration: 1000,
              mask: true,
              success: function () {
                setTimeout(function () {
                  // wx.switchTab({
                  //   url: "/pages/index/index"
                  // })
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1000);
              }
            })
          } else {
            that.setData({
              isSubmit: true
            });
            wx.showToast({
              title: '提交失败',
              icon: 'none',
              mask: true,
              duration: 1000
            })
          }
        }
      })
    } else {
      wx.showToast({
        title: '请勿重复提交',
        icon: 'none',
        mask: true,
        duration: 1000
      })
    }
  },

  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})